-- Decompiled with the Synapse X Luau decompiler.

local ClientOHOH = _G.ClientOHOH;
local CallBackManager = ClientOHOH.load.CallBackManager();
local Client_AudioManager = ClientOHOH.load.Client_AudioManager();
local BtnHelper = ClientOHOH.load.BtnHelper();
local OutOfWindowPerfab = ClientOHOH:GetPath_Loop("Perfabs.OutOfWindow", ClientOHOH.resource);
local OutOfWindow = OutOfWindowPerfab:Clone();
OutOfWindow.Transparency = 1;
OutOfWindow.AutoButtonColor = false;
local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHScreenBase());
function M.new(self, p2, p3)
	return M(self, p2, p3);
end;
function PlayBtnClick()

end;

local StaticFuc = {};
local groupUis = {};


local UIDisplayOrder = 0;
local UIShowDisplayOrder = UIDisplayOrder+1;

function StaticFuc.InitScreen(gui, displayOrder)
	gui.IgnoreGuiInset = true;
	gui.ResetOnSpawn = false;
	gui.AutoLocalize = false;
	if not displayOrder and gui.DisplayOrder ~= 1 then
		return;
	end;
	--UIDisplayOrder = UIDisplayOrder + 1;
	gui.DisplayOrder = displayOrder or UIDisplayOrder;
end;
function StaticFuc.InitAllButtons(self)
	self:AddProcess(function()
		for v15, v16 in pairs(self.main_inst:GetDescendants()) do
			if v16:IsA("GuiButton") and v16.Name ~= "OutOfWindow" then
				BtnHelper:InitButton(v16, nil, nil, nil, PlayBtnClick);
			end;
		end;
	end);
end;
local ThicknessData = {};
local BarThicknessData = {};
local ViewportSizeY = 1080 / workspace.CurrentCamera.ViewportSize.Y;

function StaticFuc.InitStrokes(self)
	self:AddProcess(function()

		for k,v in pairs(self.main_inst:GetDescendants()) do
			--v:IsA("UIStroke")

			if v:IsA("UIStroke") then
				ThicknessData[v] = v.Thickness;
				v.Thickness = v.Thickness / ViewportSizeY;
			end;
			if v:IsA("ScrollingFrame") then
				BarThicknessData[v] = v.ScrollBarThickness;
				v.ScrollBarThickness = v.ScrollBarThickness / ViewportSizeY;
			end;

		end

	end);
end;
function M.ctor(self, gui, displayOrder, isInGroup)
	StaticFuc.InitScreen(gui, displayOrder);
	M.super.ctor(self, gui);
	self.inGroup = isInGroup;
	if isInGroup then
		table.insert(groupUis, self);
	end;
	StaticFuc.InitStrokes(self);
	
	if _G.client.IsMobile then --是移动设备
		if self.insts.root then
			local pos= self.insts.root:GetAttribute("Position")
			local size=self.insts.root:GetAttribute("Size")
			
			if pos then
				self.insts.root.Position=pos
			end
			if size then
				self.insts.root.Size=size
			end
		end
	end
	
	self:subInit()
end;
function M.subInit(self)
	self:InitAllButtons()
end
function M.InitAllButtons(self)
	StaticFuc.InitAllButtons(self);
end

function M.InitOtherButton(self,element)
	
	self:AddProcess(function()
		for v15, v16 in pairs(element:GetDescendants()) do
			if v16:IsA("GuiButton")then
				BtnHelper:InitButton(v16, nil, nil, nil, PlayBtnClick);
			end;
		end;
	end);
end
function M.CloseGroupUI(self, p9)
	for v8, v9 in pairs(groupUis) do
		if v9.__is_show and v9 and v9 ~= p9 then
			v9:Hide();
		end;
	end;
end;
function M.Show(self,...)
	if self.inGroup then
		self:CloseGroupUI(self);
	end;
	self:CloseGroupUI(self);
	
	self.__is_show = true;
	M.super.Show(self,...);
end;
function M.Hide(self,...)
	self.__is_show = false;
	M.super.Hide(self,...);
end;

function M.AddStrokeListen(self, p14)
	ThicknessData[p14] = p14.Thickness;
	p14.Thickness = p14.Thickness / ViewportSizeY;
end;


function M.ListenButtonBubble(self, p21, p22, p23, p24)
	if p21:IsA("GuiButton") then
		BtnHelper:InitButton(p21, p22, p23, p24, PlayBtnClick);
	else
		local v17, v18, v19 = pairs(p21:GetChildren());
		while true do
			local v20, v21 = v17(v18, v19);
			if not v20 then
				break;
			end;
			local v22=nil
			if v21:IsA("GuiButton") then
				 v22 = v21;
			else
				v22 = v21:FindFirstChildWhichIsA("GuiButton");
			end;
			if nil and (nil).Name ~= "OutOfWindow" then
				BtnHelper:InitButton(nil, p22, p23, p24, PlayBtnClick);
			end;		
		end;
		local u8 = nil;
		p21.ChildAdded:Connect(function(p25)
			if p25:IsA("GuiButton") then
				u8 = p25;
			else
				u8 = p25:FindFirstChildWhichIsA("GuiButton");
			end;
			if u8 and u8.Name ~= "OutOfWindow" then
				BtnHelper:InitButton(u8, p22, p23, p24, PlayBtnClick);
			end;
		end);
	end;
end;
function M.GetOOw(self)
	return self.__oow;
end;
function M.CreatOOW(self, frame, p29, p30)
	assert(frame, "no frame");
	if not self.main_inst then
		warn("no main_inst!pls check", self.ClassName);
		return;
	end;
	local CloseButton = OutOfWindowPerfab:Clone();
	CloseButton.ZIndex = frame.ZIndex - 2;
	CloseButton.Parent = self.main_inst;
	CloseButton.Name="CloseButton"
	self.__oow = CloseButton;
	local OutOfWindow = OutOfWindow:Clone();
	OutOfWindow.SizeConstraint = frame.SizeConstraint;
	OutOfWindow.Size = frame.Size;
	OutOfWindow.Position = frame.Position;
	OutOfWindow.ZIndex = frame.ZIndex - 1;
	OutOfWindow.Parent = self.main_inst;
	
	local rc= frame:FindFirstChildOfClass("UIAspectRatioConstraint")
	if rc then
		rc:Clone().Parent=OutOfWindow
	end
	
	local function u9()
		OutOfWindow.Visible = false;
		frame.Visible = false;
		CloseButton.Visible = false;
	end;
	CloseButton.MouseButton1Click:Connect(function()
		--warn("$$$$$$$$$$$$$$$$$$$$$$")
		if p29 then
		--	warn("$$$$$$$$$$$$$$$$$$$$$$1")

			u9();
			return;
		end;
		self:Hide();
	end);
	if not p29 then
		return;
	end;
	--warn("$$$$$$$$$$$$$$$$$$$$$$2")

	u9();
	if p30 then
		CallBackManager:AddRbxConnect(self, p30.MouseButton1Click, function()
			u9();
		end);
	end;
	return function()
		OutOfWindow.Visible = true;
		frame.Visible = true;
		CloseButton.Visible = true;
	end, u9;
end;
local TweenHelper = ClientOHOH.load.TweenHelper();
--目前只支持竖直方向滚动
function M.GridLaySelectCell(self, scorlling, grid, cell)
	assert(scorlling, "param scorlling frame is nil");
	assert(grid, "param ui grid layout is nil");
	assert(scorlling:IsA("ScrollingFrame"), "param scorlling frame must be a ScorllingFrame");
	assert(grid:IsA("UIGridLayout"), "param ui grid layout must be a UIGridLayout");
	
	assert(grid.VerticalAlignment==Enum.VerticalAlignment.Top, "grid.VerticalAlignment~=Enum.VerticalAlignment.Top");
	assert(scorlling.ScrollingDirection==Enum.ScrollingDirection.Y, "scorlling.ScrollingDirection~=Enum.ScrollingDirection.Y");
	
	local old=scorlling.CanvasPosition
	scorlling.CanvasPosition=Vector2.zero
	-- cell间隔
	local padding=grid.CellPadding.Y.Scale*grid.AbsoluteContentSize.Y
	--起始位置
	local s=scorlling.AbsolutePosition.Y
	--cell大小
	local size=grid.AbsoluteCellSize.Y
	--结束位置
	local e=cell.AbsolutePosition.Y
	--第几行（1,2,3...)
	local c=math.floor(((e-s)/(size+padding)+1)+0.5)
	
	local endV=(c-1)*(size+padding)
	--warn("-------GridLaySelectCell------------",scorlling.CanvasPosition.Y,endV)
	scorlling.CanvasPosition=old

	TweenHelper:PlayTween(scorlling, TweenInfo.new(0.5,Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
		CanvasPosition = Vector2.new(0,endV)
	});
	
end

--自动扩张滚动范围
function M.InitUIGridLay(self, scorlling, grid, p34)
	
	assert(scorlling, "param scorlling frame is nil");
	assert(grid, "param ui grid layout is nil");
	assert(scorlling:IsA("ScrollingFrame"), "param scorlling frame must be a ScorllingFrame");
	assert(grid:IsA("UIGridLayout"), "param ui grid layout must be a UIGridLayout");
	
	CallBackManager:AddRbxConnect(self, grid.Changed, function(p35, p36)
		if p36 == "AbsoluteCellCount" then
			
			--print("InitUIGridLayInitUIGridLay-->",p35,p36)
			
			local scale_g2s_x = grid.AbsoluteContentSize.X / scorlling.AbsoluteCanvasSize.X;
			local scale_g2s_y = grid.AbsoluteContentSize.Y / scorlling.AbsoluteCanvasSize.Y;
			local s_x = scorlling.CanvasSize.X.Scale * scale_g2s_x;
			local s_y = scorlling.CanvasSize.Y.Scale * scale_g2s_y;
			if s_x <= scorlling.CanvasSize.X.Scale and s_y <= scorlling.CanvasSize.Y.Scale then
				return;
			end;
			local g_x = grid.CellSize.X.Scale / scale_g2s_x;
			local g_y = grid.CellSize.Y.Scale / scale_g2s_y;
			local p_x = grid.CellPadding.X.Scale / scale_g2s_x;
			local p_y = grid.CellPadding.Y.Scale / scale_g2s_y;
			if p34 then
				if scorlling.ScrollingDirection == Enum.ScrollingDirection.X then
					s_y = scorlling.CanvasSize.Y.Scale;
					g_y = grid.CellSize.Y.Scale;
					p_y = grid.CellPadding.Y.Scale;
				elseif scorlling.ScrollingDirection == Enum.ScrollingDirection.Y then
					s_x = scorlling.CanvasSize.X.Scale;
					g_x = grid.CellSize.X.Scale;
					p_x = grid.CellPadding.X.Scale;
				end;
			end;
			scorlling.CanvasSize = UDim2.fromScale(s_x, s_y);
			grid.CellSize = UDim2.fromScale(g_x, g_y);
			grid.CellPadding = UDim2.fromScale(p_x, p_y);
		end;
	end);
end;
function M.InitCloseBtn(self, p38)
	p38.MouseButton1Click:Connect(function()
		self:Hide();
	end);
end;
(function()
	workspace.CurrentCamera:GetPropertyChangedSignal("ViewportSize"):Connect(function()
		ViewportSizeY = 1080 / workspace.CurrentCamera.ViewportSize.Y;
		for v38, v39 in pairs(ThicknessData) do
			v38.Thickness = v39 / ViewportSizeY;
		end;
		for v40, v41 in pairs(BarThicknessData) do
			v40.ScrollBarThickness = v41 / ViewportSizeY;
		end;
	end);
end)();
return M;
